﻿//using System;
//using System.ComponentModel.DataAnnotations.Schema;
//using System.Linq;
//using System.Linq.Expressions;
//using System.Reflection;
//using System.Text;
//using NiuX.Common.Tests.Dapper.Visitors;

//namespace NiuX.Common.Tests.Dapper;

//public class SelectVisitor : DbVisitor
//{
//    public StringBuilder ConditionSql = new StringBuilder();


//    //public string ResolveExpression<T>(Expression<Func<T, T>> exp)
//    //{
//    //    Visit(exp.Body);
//    //    return ConditionSql.ToString();
//    //}

//    //protected override Expression VisitBinary(BinaryExpression node)
//    //{
//    //    ConditionSql.Append("(");
//    //    Visit(node.Left);

//    //    ConditionSql.Append($" {node.NodeType.TransferExpressionType()} ");

//    //    Visit(node.Right);
//    //    ConditionSql.Append(")");

//    //    return node;
//    //}

//    protected override Expression VisitMember(MemberExpression node)
//    {
//        ConditionSql.Append(node.Member.Name);
//        return node;
//    }

//    protected override Expression VisitMemberInit(MemberInitExpression node)
//    {

//        foreach (var binding in node.Bindings.Select(x => (MemberAssignment)x))
//        {
//            //ConditionSql.Append(binding.Member.Name);


//            switch (binding.Expression.NodeType)
//            {
//                case ExpressionType.Constant:
//                    var constantExpression = (ConstantExpression)binding.Expression;
//                    ConditionSql.Append($"{constantExpression.Value} AS `{binding.Member.Name}`");
//                    break;
//                case ExpressionType.MemberAccess:
//                    var constantValue = ((MemberExpression)binding.Expression);
//                    var name = constantValue.Member.GetCustomAttribute<ColumnAttribute>()?.Name ?? constantValue.Member.Name;
//                    ConditionSql.Append($"`{name}` AS `{binding.Member.Name}`");
//                    break; ;
//            }


//            ConditionSql.Append(",");
//        }
//        ConditionSql.RemoveLastChar();

//        return node;
//    }
//}